package com.rran.study.designpattern.behavioral.observer.service;

import com.rran.study.designpattern.behavioral.observer.event.spring.RranEvent;
import com.rran.study.designpattern.behavioral.observer.model.Rran;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

/**
 * @author yy
 * @Type RranEventService.java
 * @Desc
 * @date 2020/7/21 20:53
 */
@Service
public class RranEventService implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher applicationEventPublisher;

    public void publishRran() throws Exception{
        Rran rran = new Rran();
//        rran.setName("yy");
//        rran.setAge(18);
        System.out.println("rran 开始发布任务");
        applicationEventPublisher.publishEvent(new RranEvent(rran));
        System.out.println("rran 发布任务完成");

    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher= applicationEventPublisher;
    }
}
